﻿using DM_IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DM_BLL
{
    public class BLL_Base<T> where T : class, new()
    {
        public IDAL_Base<T>? CurrentDal { get; set; }
        public IQueryable<T> LoadEntities
         (System.Linq.Expressions.Expression<Func<T, bool>> whereLambda)
        {
            if (CurrentDal != null)
            {
                return CurrentDal.LoadEntities(whereLambda);
            }
            else
            {
                throw new Exception();
            }

        }

        public bool DeleteEntity(T entity)
        {
            if (CurrentDal != null)
            {
                CurrentDal.DeleteEntity(entity);
                return CurrentDal.SaveChanges();
            }
            else
            {
                throw new Exception();
            }
        }
        public bool EditEntity(T entity)
        {
            if (CurrentDal != null)
            {
                CurrentDal.EditEntity(entity);
                return CurrentDal.SaveChanges();
            }
            else
            {
                throw new Exception();
            }
        }
        public bool AddEntity(T entity)
        {
            if (CurrentDal != null)
            {
                CurrentDal.AddEntity(entity);
                return CurrentDal.SaveChanges();
            }
            else
            {
                throw new Exception();
            }
        }
    }
}
